package com.qf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.qf.entity.Result;
import com.qf.mapper.SetMealMapper;
import com.qf.pojo.Setmeal;
import com.qf.service.SetMealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetMealController {

    @Autowired
    private SetMealService setMealService;

    /**
     * 获得所有套餐信息
     */
    @RequestMapping("/getSetMeal")
    public Result getSetMeal(){
        try{
            List<Setmeal> list = setMealService.list();
            System.out.println("成功");
            return Result.success("查询成功"+list);
        }catch (Exception e){
            e.printStackTrace();
            System.out.println("失败");
            return Result.error("查询失败");
        }
    }
    /**
     * 从前端得到套餐的id
     * 根据套餐id得到套餐信息
     */
    @RequestMapping("/findById")
    public Result findById(Integer id){
        try{
            Setmeal setmeal = setMealService.findById(id);
            return  Result.success("成功"+setmeal);
        }catch (Exception e){
            e.printStackTrace();
            return Result.error("失败");
        }
    }

//    /**
//     * 根据性别查询套餐
//     * @param sex
//     * @return
//     */
//    @RequestMapping("/findBySex")
//    public Result findSetMealBySex(Integer sex){
//        try{
//            sex=0;
//            QueryWrapper<Setmeal> queryWrapper = new QueryWrapper<>();
//            queryWrapper.eq("sex",sex);
//            List<Setmeal> list = setMealService.list(queryWrapper);
////            List<Setmeal> setmeals = setMealMapper.selectList(null);
//            System.out.println("成功");
//            return Result.success("查询成功"+list);
//        }catch (Exception e){
//            e.printStackTrace();
//            System.out.println("失败");
//            return Result.error("查询失败");
//        }
//    }
}
